package com.translate.web.api.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.param.impl.IdPageParam;
import com.param.impl.IdParam;
import com.translate.vo.TranslatorsAssociationVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.translate.web.param.TranslatorsAssociationUpdateParam;
import com.translate.web.constant.RedisConstant;
import com.translate.web.param.TranslatorsAssociationAddParam;
import com.translate.entity.TranslatorsAssociation;
import com.translate.web.service.ITranslatorsAssociationService;
import com.basic.service.contract.IBaseService;

@RestController
@RequestMapping("translatorsAssociation")
public class TranslatorsAssociationController extends AbstractCommonController<TranslatorsAssociation, IdPageParam> {
	private ITranslatorsAssociationService service;

	public TranslatorsAssociationController(ITranslatorsAssociationService service) {
		this.service = service;
	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated TranslatorsAssociationAddParam param,
			HttpServletRequest httpServletRequest) {
		int id = this.service.parseInsert(param, TranslatorsAssociation.class);

		return ResponseModel.<Integer>success(id);
	}
	
	
	@PostMapping("/translatorsAssociation")
	public ResponseModel<List<TranslatorsAssociation>> translatorsAssociation() {
		
		List<TranslatorsAssociation> articleById = 
				this.service.listToCache(
						RedisConstant.TRANSLATORS_ASSOCIATION,
						6);
		
		return ResponseModel.success(articleById);

	}
	

	@Override
	protected IBaseService<TranslatorsAssociation> getBaseService() {
		return this.service;
	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody TranslatorsAssociationUpdateParam param,
			HttpServletRequest httpServletRequest) {
		int res = this.service.parseUpdate(param, TranslatorsAssociation.class);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) TranslatorsAssociationVO.class;
	}
}